package com.greendragon.service.frontend.impl; 

import java.util.List;

import com.greendragon.persistence.dao.IArticalDao;
import com.greendragon.persistence.dao.ICategoryDao;
import com.greendragon.persistence.dao.ICommentDao;
import com.greendragon.persistence.domain.Artical;
import com.greendragon.persistence.domain.ArticalCategory;
import com.greendragon.persistence.domain.ArticalComment;
import com.greendragon.persistence.enmu.FetchOrderType;
import com.greendragon.persistence.enmu.LockType;
import com.greendragon.persistence.enmu.VerifyType;
import com.greendragon.service.frontend.IArticalFrontendService;


/** 
 * @author wulibin, exceptsky@gmail.com, 2011-9-9 上午07:23:30
 * 
 */
public class ArticalFrontendService extends BaseFrontendService<Artical> implements IArticalFrontendService{
	private ICommentDao<ArticalComment> commentDao;
	private IArticalDao articalDao;
	private ICategoryDao<ArticalCategory> categoryDao;
	
	@Override
	public List<Artical> getByCategory(Long cid, int page) {
		Artical expArtical = new Artical();
		expArtical.setCategory(categoryDao.get(cid));
		expArtical.setBlock(false);
		return this.getByCondition(expArtical, page);
	}

	@Override
	public long getCommentCount(Long aid) {
		return commentDao.getCountOfObj(aid, LockType.UNLOCK, VerifyType.VERIFY);
	}

	@Override
	public List<ArticalComment> getComments(Long aid, int page) {
		return commentDao.getOfObj(aid, pageLength*page, pageLength, LockType.UNLOCK, VerifyType.VERIFY,FetchOrderType.CREATE_DESC);
	}

	@Override
	public long getCountByCategory(Long cid) {
		Artical expArtical = new Artical();
		expArtical.setCategory(categoryDao.get(cid));
		expArtical.setBlock(false);
		return this.getCountByCondition(expArtical);
	}
	
	public void setCommentDao(ICommentDao<ArticalComment> commentDao) {
		this.commentDao = commentDao;
	}

	public void setArticalDao(IArticalDao articalDao) {
		this.articalDao = articalDao;
		this.setDao(this.articalDao);
	}

	public void setCategoryDao(ICategoryDao<ArticalCategory> categoryDao) {
		this.categoryDao = categoryDao;
	}

}
 